var $ = jQuery.noConflict(); (function (window, $) { "use strict"; var defaultConfig = { type: '', autoDismiss: false, container: '#cstm-toasts', autoDismissDelay: 4000, transitionDuration: 500 }; $.toast = function (config) { var size = arguments.length; var isString = typeof (config) === 'string'; if (isString && size === 1) { config = { message: config }; } if (isString && size === 2) { config = { message: arguments[1], type: arguments[0] }; } return new toast(config); }; var toast = function (config) { config = $.extend({}, defaultConfig, config); // show "x" or not var close = config.autoDismiss ? '' : '×'; // toast template var toast = $([ '
', '

' + config.message + '

', '
' + close + '
', '
' ].join('')); // handle dismiss toast.find('.close').on('click', function () { var toast = $(this).parent(); toast.addClass('hide'); setTimeout(function () { toast.remove(); }, config.transitionDuration); }); // append toast to toasts container $(config.container).append(toast); // transition in setTimeout(function () { toast.addClass('show'); }, config.transitionDuration); // if auto-dismiss, start counting if (config.autoDismiss) { setTimeout(function () { toast.find('.close').click(); }, config.autoDismissDelay); } return this; }; })(window, jQuery); $(document).ready(function () { $('#items_per_page').change(function() { console.log('items_per_page changed'); $('#items_per_page_form').submit(); }); $(".alert").fadeTo(2000, 500).slideUp(500, function () { $(".alert").slideUp(500); }); // DataTable start $('#pages-list').DataTable({ "pagingType": "full_numbers" }); $('#product-table').DataTable({ "searching": true }); $('#placeholder-tag-table').DataTable({ "searching": true }); $(".category-multiple").select2(); $('input[name="publish"]').daterangepicker({ singleDatePicker: true, showDropdowns: true, minYear: 1901, maxYear: parseInt(moment().format('YYYY'), 10) }, function (start, end, label) { var years = moment().diff(start, 'years'); alert("You are " + years + " years old!"); }); // start accordion javascript // Currently used on Customize View General Settings on Dashboard var acc = document.getElementsByClassName("accordion"); for (var i = 0; i < acc.length; i++) { acc[i].addEventListener("click", function(e) { e.preventDefault(); this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.minHeight) { panel.style.maxHeight = null; panel.style.minHeight = null; } else { var newHeight = panel.scrollHeight + 160; panel.style.minHeight = newHeight + "px"; } }); } // end accordion javascript $('.demo').each(function () { $(this).minicolors({ control: $(this).attr('data-control') || 'hue', defaultValue: $(this).attr('data-defaultValue') || '', format: $(this).attr('data-format') || 'hex', keywords: $(this).attr('data-keywords') || '', inline: $(this).attr('data-inline') === 'true', letterCase: $(this).attr('data-letterCase') || 'lowercase', opacity: $(this).attr('data-opacity'), position: $(this).attr('data-position') || 'bottom', swatches: $(this).attr('data-swatches') ? $(this).attr('data-swatches').split('|') : [], change: function (value, opacity) { if (!value) return; if (opacity) value += ', ' + opacity; if (typeof console === 'object') { } }, theme: 'bootstrap' }); }); }); /************** For Company Details Page *********************/ // on upload button click jQuery(document).on('click', '.cimg-upl', function (e) { e.preventDefault(); var did = jQuery(this).attr("data-id"); var button = jQuery(this), custom_uploader = wp.media({ title: 'Insert image', library: { type: 'image' }, button: { text: 'Use this image' // button label text }, multiple: true }).on('select', function () { var attachment = custom_uploader.state().get('selection').first().toJSON(); button.removeClass('btn'); button.removeClass('btn-primary'); button.html('').next('.cimg-rmv').show(); }).open(); }); // on remove button click jQuery(document).on('click', '.cimg-rmv', function (e) { e.preventDefault(); let did = jQuery(this).data('id'); var button = jQuery(this); button.next().val(''); // emptying the hidden field button.hide().prev().html('Upload image'); button.prev().addClass('btn btn-primary'); button.prev().attr("data-id", did); }); /********************* For Featured Images and Aditional Images Upload ******************/ // on upload button click jQuery(document).on('click', '.img-upl', function (e) { e.preventDefault(); let thiselm = jQuery(this); let button = jQuery(this); let did = jQuery(this).data('id'); let upl_txt = jQuery(this).text(); file_frame = wp.media.frames.file_frame = wp.media({ title: 'Insert Image or Video', button: { text: 'Use this file', }, multiple: false // set this to true for multiple file selection }); file_frame.on('select', function () { attachment = file_frame.state().get('selection').first().toJSON(); button.removeClass('btn'); button.removeClass('btn-primary'); var imgExtension = ['heic', 'jpeg', 'jpg', 'png', 'gif', 'svg', 'bmp', 'tiff', 'webp']; var videoExtension = ['hevc', 'mp4', '.m4v', 'mov', '3gp', 'wmv', 'avi', 'mkv', 'webm', 'mpg', 'mpeg-2']; var validExtension = imgExtension.concat(videoExtension); var fileExtension = attachment.url.substr((attachment.url.lastIndexOf('.') + 1)); if (upl_txt == 'Upload Video') { if ($.inArray(fileExtension, videoExtension) == -1) { Swal.fire('Error Occured', 'Please upload video file only. \n Allowed formats are: ' + videoExtension, 'error' ) return; } var img = 'https://' + location.hostname + '/wp-content/themes/Divi-child/for-custom/js/video-icon.jpg'; button.html('').next('.img-rmv').show(); } else if (upl_txt == 'Upload Media') { if ($.inArray(fileExtension, validExtension) == -1) { // uploaded file not defined for upload Swal.fire('Error Occured', 'Allowed formats are : \n' + validExtension.join(', '), 'error' ) } else if ($.inArray(fileExtension, imgExtension) == -1) { // uploaded file is a video var img = 'https://' + location.hostname + '/wp-content/themes/Divi-child/for-custom/js/video-icon.jpg'; button.html('').next('.img-rmv').show(); } else { // uploaded file is an image button.html('').next('.img-rmv').show(); } } else { if ($.inArray(fileExtension, imgExtension) == -1) { Swal.fire('Error Occured', 'Please upload image file only. \n Allowed formats are: ' + imgExtension, 'error' ) return; } button.html('').next('.img-rmv').show(); } console.log(attachment); thiselm.parent('.form-group').children("input[name^='" + did + "']").val(attachment.id); file_frame.close(); }); if (file_frame) { file_frame.open(); return; } }); // on remove button click jQuery(document).on('click', '.img-rmv', function (e) { e.preventDefault(); let did = jQuery(this).data('id'); let upl_txt = jQuery(this).text(); var button = jQuery(this); button.next().val(''); // emptying the hidden field if (upl_txt == 'Remove Video') { button.hide().prev().html('Upload Video'); } else if (upl_txt == 'Remove Media') { button.hide().prev().html('Upload Media'); } else { button.hide().prev().html('Upload image'); } button.prev().addClass('btn btn-primary'); button.prev().attr("data-id", did); }); //Update Company Details jQuery(document).on('click', '#update-company', function (e) { var bt = jQuery(this); e.preventDefault(); var companyid = jQuery(this).val(); var companyname = jQuery("#companyname").val(); var company_logo = jQuery('#company_logo').attr('src'); var favicon = jQuery('#favicon').attr('src'); var company_address = jQuery("#company_address").val(); var city = jQuery("#city").val(); var state = jQuery("#state").val(); var country = jQuery("#country").val(); var zip = jQuery("#zip").val(); var representative_name = jQuery("#representative_name").val(); var phone_number = jQuery("#phone_number").val(); var fax = jQuery("#fax").val(); var customerid = jQuery("#customerid").val(); var role = jQuery("#role").val(); var user_id = jQuery("#user_id").val(); var incorporation_year = jQuery("#incorporation_year").val(); var major_markets = jQuery("#major_markets").val(); var export_market = jQuery("#export_market").val(); var exports = jQuery("#cexports").val(); var imports = jQuery("#imports").val(); var services = jQuery("#services").val(); var standards = jQuery("#standards").val(); var image_url = jQuery('#image_url').attr('src'); var company_img1 = jQuery('#company_image1').attr('src'); var company_img2 = jQuery('#company_image2').attr('src'); var about_company1 = jQuery("#about_company1").val(); var about_company2 = jQuery("#about_company2").val(); var about_company3 = jQuery("#about_company3").val(); var about_company_management_intro = jQuery("#about_company_management_intro").val(); var about_company_management1 = jQuery("#about_company_management1").val(); var about_company_management3 = jQuery("#about_company_management3").val(); var about_company_management2 = jQuery("#about_company_management2").val(); var company_management_image1 = jQuery('#company_management_image1').attr('src'); var company_management_image2 = jQuery('#company_management_image2').attr('src'); var company_management_image3 = jQuery('#company_management_image3').attr('src'); var company_news_intro = jQuery("#company_news_intro").val(); var company_news1 = jQuery("#company_news1").val(); var company_news2 = jQuery("#company_news2").val(); var company_news3 = jQuery("#company_news3").val(); var company_news_image1 = jQuery('#company_news_image1').attr('src'); var company_news_image2 = jQuery('#company_news_image2').attr('src'); var company_news_image3 = jQuery('#company_news_image3').attr('src'); var facility_image = jQuery('#facility_image').attr('src'); var facilities_advantage = jQuery("#facilities_advantage").val(); var facilities_material = jQuery("#facilities_material").val(); var facilities_machinery = jQuery("#facilities_machinery").val(); var company_fb = jQuery("#company_fb").val(); var company_twitter = jQuery("#company_twitter").val(); var company_linkedin = jQuery("#company_linkedin").val(); var company_insta = jQuery("#company_insta").val(); var blog_id = jQuery("#blog_id").val(); console.log(companyid + 'two'); if (favicon && (!icoValidation(favicon))) { Swal.fire('Error Occured', 'Please make sure your uploaded Favicon is an .ico image only ', 'error' ) return false; } if (!incorporation_year) { Swal.fire('Error Occured', 'Please enter Business year ', 'error' ) return false; } if (incorporation_year.length != 4) { Swal.fire('Error Occured', 'Please enter appropriate Business year ', 'error' ) return false; } if (companyid) { jQuery(bt).find('.feather').addClass('show'); jQuery.ajax({ url: go4ajax_object.ajax_url, method: "POST", data: { 'action': 'update_company', 'companyid': companyid, 'companyname': companyname, 'company_logo': company_logo, 'favicon': favicon, 'image_url': image_url, 'company_address': company_address, 'city': city, 'state': state, 'country': country, 'zip': zip, 'representative_name': representative_name, 'phone_number': phone_number, 'fax': fax, 'customerid': customerid, 'role': role, 'user_id': user_id, 'incorporation_year': incorporation_year, 'major_markets': major_markets, 'export_market': export_market, 'exports': exports, 'imports': imports, 'services': services, 'standards': standards, 'company_img1': company_img1, 'company_img2': company_img2, 'about_company1': about_company1, 'about_company2': about_company2, 'about_company3': about_company3, 'company_management_image1': company_management_image1, 'company_management_image2': company_management_image2, 'company_management_image3': company_management_image3, 'about_company_management_intro': about_company_management_intro, 'about_company_management1': about_company_management1, 'about_company_management2': about_company_management2, 'about_company_management3': about_company_management3, 'company_news_intro': company_news_intro, 'company_news1': company_news1, 'company_news2': company_news2, 'company_news3': company_news3, 'company_news_image1': company_news_image1, 'company_news_image2': company_news_image2, 'company_news_image3': company_news_image3, 'facility_image': facility_image, 'facilities_advantage': facilities_advantage, 'facilities_material': facilities_material, 'facilities_machinery': facilities_machinery, 'company_fb': company_fb, 'company_twitter': company_twitter, 'company_linkedin': company_linkedin, 'company_insta': company_insta, 'blog_id': blog_id }, success: function (data) { console.log(data); jQuery(bt).find('.feather').removeClass('show'); Swal.fire("Good job!", "Company Details Successfully Updated", "success"); } }); } else { jQuery('#url_show').hide(); } }); jQuery(document).on('click', '#editCompany', function () { jQuery(".company_wrap .toHide").css({ "display": "none" }); jQuery(".company_wrap .toShow").css({ "display": "block" }); }); jQuery(document).on('click', '#cancelEditCompany', function () { jQuery(".company_wrap .toHide").css({ "display": "block" }); jQuery(".company_wrap .toShow").css({ "display": "none" }); }); jQuery(document).on('click', '#addCategory', function (e) { e.preventDefault(); jQuery(".category_sec .toHide").css({ "display": "none" }); jQuery(".category_sec .toShow").css({ "display": "block" }); }); jQuery(document).on('click', '#cancelAddCategory', function (e) { e.preventDefault(); jQuery(".category_sec .toHide").css({ "display": "inline-block" }); jQuery(".category_sec .toShow").css({ "display": "none" }); }); /********** Dashboard Sample Available **********/ jQuery('#sampleCheck').click(function () { console.log("checked"); jQuery(".show_sample").toggle(this.checked); }); // Update as Featured jQuery(document).on('click', '.featured-product', function (e) { e.preventDefault(); var curElm = jQuery(this); var product_id = jQuery(this).attr("data-pid"); var site_id = jQuery(this).attr("data-site"); if (product_id) { jQuery.ajax({ url: go4ajax_object.ajax_url, method: "POST", data: { 'action': 'set_as_featured', 'product_id': product_id, 'site_id': site_id }, success: function (data) { console.log(data); if (curElm.is(':checked')) { console.log(curElm); curElm.prop("checked", false); } else { curElm.prop("checked", true); } } }); } else { return; } }); // Update category as featured jQuery(document).on('click', '.featured-category', function (e) { e.preventDefault(); var curElm = jQuery(this); var category_id = jQuery(this).attr("data-catid"); var site_id = jQuery(this).attr("data-site"); if (category_id) { jQuery.ajax({ url: go4ajax_object.ajax_url, method: "POST", data: { 'action': 'set_as_featured_category', 'category_id': category_id, 'site_id': site_id }, success: function (data) { console.log(data); if (curElm.is(':checked')) { console.log(curElm); curElm.prop("checked", false); } else { curElm.prop("checked", true); } } }); } else { return; } }); jQuery('#add_product #submitBtn').on('click', function (e) { e.preventDefault(); var prodcat = []; var product_cat = document.getElementsByName("product_cat[]"); var product_name = jQuery("#productname").val(); var product_desc_text = jQuery("#product_desc").val(); var product_desc = tinyMCE.get('product_desc').getContent(); var product_short_desc = jQuery("#short_desc").val(); var product_price = jQuery("#productprice").val(); console.log(product_cat, product_name, product_desc, product_short_desc, product_price); for (var pc = 0; pc < product_cat.length; pc++) { console.log("lookingfor forloop"); if (product_cat[pc].checked) { console.log("lokking checked"); prodcat.push(product_cat[pc]); } } console.log(prodcat); tinyMCE.triggerSave(); console.log('ajax url: '+ go4ajax_object.ajax_url); console.log(jQuery('#post-a').serialize()); if (prodcat.length !== 0 && product_name != '' && (product_desc.trim().length > 0 || product_desc_text.trim().length > 0) && product_short_desc.trim().length > 0) { jQuery('#ajax-loader').show(); jQuery.ajax({ url: go4ajax_object.ajax_url, dataType: "json", method: 'POST', data: jQuery('#post-a').serialize(), success: function (response) { console.log(response); // JSON.parse(response); if (response.data.post_id) { jQuery('#ajax-loader').hide(); let pid = response.data.post_id; let prourl = response.data.product_url; let listurl = response.data.products_list; console.log(prourl); console.log(listurl); Swal.fire({ title: 'Product Created Successfully', icon: "success", allowEscapeKey: false, allowOutsideClick: false, showConfirmButton: false, footer: 'See how others see your product' + 'Back to your product list' }); } else { jQuery('#ajax-loader').hide(); Swal.fire('Error Occured', 'Please Try After Some Time', 'error' ) } }, error: function (err) { jQuery('#ajax-loader').hide(); console.log('form err.'); console.log(err); }, }); } else { Swal.fire("Error!", "Fields with * are required Fields", "warning"); } }); jQuery('#edit_product #submitBtn').on('click', function (e) { var product_name = jQuery("#name").val(); var product_desc_text = jQuery("#kv_frontend_editor_desc").val(); var product_desc = ''; if(tinyMCE.get('kv_frontend_editor_desc')){ product_desc = tinyMCE.get('kv_frontend_editor_desc').getContent(); } var product_short_desc = jQuery("#short_description").val(); var product_price = jQuery("#productprice").val(); if (product_name.length !== 0 && (product_desc.length !== 0 || product_desc_text.trim().length !== 0) && product_short_desc.trim().length !== 0) { $('#ajax-loader').show(); } else if (product_desc.trim().length == 0 && product_desc_text.trim().length == 0) { e.preventDefault(); Swal.fire("Error!", "Fields with * are required Fields", "warning"); } }); jQuery('.deletePage').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); let pid = e.target.getAttribute('data-id'); console.log(pid); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) { $('#ajax-loader').show(); window.location.replace(durl); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire('Cancelled', 'Your Page is safe :)', 'error' ) } }); }); jQuery('.deleteProduct').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) { $('#ajax-loader').show(); window.location.replace(durl); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire('Cancelled', 'Your Product is safe :)', 'error' ) } }); }); jQuery('.deleteProCat').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) { $('#ajax-loader').show(); window.location.replace(durl); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire('Cancelled', 'Your Category is safe :)', 'error' ) } }); }); jQuery('.deletePostCat').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); Swal.fire({ title: "Are you sure. You want to delete this Category?", icon: "warning", buttons: true, dangerMode: true, }) .then((willDelete) => { if (willDelete) { $('#ajax-loader').show(); window.location.replace(durl); } else { Swal.fire("Your Category is safe!", { icon: "error", }); } }) }); jQuery('.deleteInquire').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) { $('#ajax-loader').show(); window.location.replace(durl); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire('Cancelled', 'Your Inquire is safe :)', 'error' ) } }); }); jQuery('.deletePost').on('click', function (e) { e.preventDefault(); let durl = e.target.getAttribute('href'); Swal.fire({ title: "Are you sure?", text: "You won't be able to revert this!", icon: "warning", showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) { $('#ajax-loader').show(); window.location.replace(durl); } else if (result.dismiss === Swal.DismissReason.cancel) { Swal.fire('Cancelled', 'Your Post is safe :)', 'error' ) } }); }); function icoValidation(image) { var isValid = /\.ico$/i.test(image); if (!isValid) { return false; } return true; } // Upload company logo, favicon and footer background image // show error if favicon image uploaded is not an .ico jQuery('#customizationBtn').click(function(e){ // e.preventDefault(); // e.stopPropagation(); var favicon = jQuery('#favicon').attr('src'); var favicon_data_src = jQuery('#favicon').attr('data-src'); var company_logo = jQuery('#company_logo').attr('src'); var footer_background_image = jQuery('#footer_background_image').attr('src'); if(typeof footer_background_image == 'undefined'){ footer_background_image = ''; } var site_id = jQuery("#site_id").val(); var fb_link = jQuery("#fb-link").val(); if(fb_link == undefined){ fb_link = ""; } var twitter_link = jQuery("#twitter-link").val(); if(twitter_link == undefined){ twitter_link = ""; } var linkedin_link = jQuery("#linkedin-link").val(); if(linkedin_link == undefined){ linkedin_link = ""; } var insta_link = jQuery("#insta-link").val(); if(insta_link == undefined){ insta_link = ""; } var font_length_true = 1; var template_type = jQuery("#templateType").length; if(template_type){ var banner_heading_font_size_len = jQuery("#banner_heading_font_size").val().length; var banner_text_font_size_len = jQuery("#banner_text_font_size").val().length; var banner_button_font_size_len = jQuery("#banner_button_font_size").val().length; var heading_font_size_len = jQuery("#heading_font_size").val().length; var sub_heading_font_size_len = jQuery("#sub_heading_font_size").val().length; var text_font_size_len = jQuery("#text_font_size").val().length; var button_font_size_len = jQuery("#button_font_size").val().length; var background_font_size_len = jQuery("#background_font_size").val().length; if((banner_heading_font_size_len > 2) || (banner_text_font_size_len > 2) || (banner_button_font_size_len > 2) || (heading_font_size_len > 2) || (sub_heading_font_size_len > 2) || (text_font_size_len > 2) || (button_font_size_len > 2) || (background_font_size_len > 2)){ font_length_true = 0; } } if(((fb_link !== '' && validURL(fb_link) !== true) || (twitter_link !== '' && validURL(twitter_link) !== true) || (linkedin_link !== '' && validURL(linkedin_link) !== true) || (insta_link !== '' && validURL(insta_link) !== true)) || (font_length_true == 0)){ Swal.fire('Error Occured', 'Please make sure valid social links ', 'error' ) return true; } else { if (favicon && (!icoValidation(favicon) && !icoValidation(favicon_data_src))) { Swal.fire('Error Occured', 'Please make sure your uploaded Favicon is an .ico image only ', 'error' ) return false; } jQuery('#ajax-loader').show(); jQuery.ajax({ url: go4ajax_object.ajax_url, method: "POST", data: { 'action': 'update_favicon_and_logo', 'favicon': favicon, 'company_logo': company_logo, 'footer_background_image': footer_background_image, 'site_id': site_id }, success: function (data) { jQuery('#ajax-loader').hide(); console.log(data); Swal.fire("Good job!", "Details Successfully Updated", "success"); }, error: function (err) { jQuery('#ajax-loader').hide(); console.log('Image upload form err.'); console.log(err); Swal.fire("Error!!!", "Please try again", "error"); } }); console.log('Purge cache from customization save'); var show_message = false; purge_cache(show_message); } }); // copy text to clipboard jQuery(document).on('click', '.copy-text', function (e) { // get the text from the DOM Element: var textToCopy = jQuery(this).text(); var formattedText = textToCopy.replace('<', '<'); formattedText = formattedText.replace('>', '>'); formattedText = formattedText.trim(); navigator.clipboard.writeText(textToCopy).then( function () { /* clipboard successfully set */ Swal.fire(formattedText, "Copied Successfully", "success"); }, function () { /* clipboard write failed */ Swal.fire("Error!", "Problem copying text. Please try again", "error"); } ) }); function validURL(str) { var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string '(\\#[-a-z\\d_]*)?$','i'); // fragment locator return !!pattern.test(str); } function purge_cache(show_message = true){ jQuery.ajax({ url: go4ajax_object.ajax_url, data: { 'action': 'purge_cache_through_wc' }, success: function () { console.log('Purged Successfully'); if(show_message){ Swal.fire("Site", "Purged Successfully", "success"); } location.reload(); }, error: function (err) { console.log(err); } }); } jQuery('.purge_cache_through_wc').click(function(e){ console.log('purge cache using purge button') e.preventDefault(); purge_cache(); }); jQuery(function($) { jQuery('#submitCategory').click(function(event) { // Show the loader jQuery('#ajax-loader').show(); }); });